package com.leyou.page.web;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("page")
public class PageController {
    @Autowired
    private PageService pageService;

    /**
     * 查询spu信息
     * @param spuId  商品id
     * @return  商品名
     */
    @GetMapping("spu/{id}")
    public ResponseEntity<String> querySpuVoPage(@PathVariable("id") Long spuId){
        return ResponseEntity.ok(pageService.loadSpuVo(spuId));
    }

    /**
     *  查询sku信息
     * @param spuId 商品id
     * @return sku数据
     */
    @GetMapping("/sku/{id}")
    public ResponseEntity<String> querySkuPage(@PathVariable("id") Long spuId){
        return ResponseEntity.ok(pageService.loadSkuList(spuId));
    }

    /**
     *  查询spuDetail数据
     * @param spuId 商品id
     * @return  spu详细数据
     */
    @GetMapping("/detail/{id}")
    public ResponseEntity<String> querySpuDetail(@PathVariable("id") Long spuId){
        return ResponseEntity.ok(pageService.loadSpuDetail(spuId));
    }

    /**
     *  查询商品分类的数据
     * @param ids
     * @return
     */
    @GetMapping("/categories")
    public ResponseEntity<String>queryCategory(@RequestParam("ids")List<Long> ids){
        return ResponseEntity.ok(pageService.loadCategories(ids));
    }

    /**
     *  查询品牌数据
     * @param id 品牌id
     * @return spu数据
     */
    @GetMapping("/brand/{id}")
    public ResponseEntity<String>queryBrand(@PathVariable("id") Long id){
        return ResponseEntity.ok(pageService.loadBrand(id));
    }

    @GetMapping("/spec/{id}")
    public ResponseEntity<String> querySpec(@PathVariable("id") Long categoryId){
        return ResponseEntity.ok(pageService.loadSpec(categoryId));
    }
}
